package com.linwen.excise.leetcode;

/**
 * @ClassName _1422分割字符串的最大得分
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/22 10:21 AM
 * @Version 1.0
 */
public class _1422分割字符串的最大得分 {
    public static void main(String[] args) {
        _1422分割字符串的最大得分 inst = new _1422分割字符串的最大得分();
        System.out.println(inst.maxScore("011101"));

    }

    public int maxScore(String s) {
        int res = 0;
        if (s.charAt(0) == '0') {
            res++;
        }
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                res++;
            }
        }
        int max = res;
        for (int i = 1; i < s.length() - 1; i++) {
            if (s.charAt(i) == '0') {
                res++;
            } else {
                res--;
            }
            max = Math.max(res, max);
        }
        return max;
    }
}
